/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   10.05.2010
 * @version SVN: $Id: ClientSessionAccessInterceptor.java 120 2010-05-11 20:11:01Z christian-kerl@web.de $
 */
package org.cakis.server.service.session;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.jboss.seam.Component;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;

/**
 * ClientSessionAccessInterceptor
 *
 * @author Christian Kerl
 */
public class ClientSessionAccessInterceptor {
    private final Log log = Logging.getLog(getClass());

    @AroundInvoke
    public Object intercept(InvocationContext ctx) throws Exception {
        ClientSession session = (ClientSession) Component.getInstance(ClientSession.class, false);
        if(session != null && session.isInited()) {
            session.access();
        } else {
            log.warn(
                    "Call to Method #0::#1 without active ClientSession!",
                    ctx.getMethod().getDeclaringClass().getSimpleName(),
                    ctx.getMethod().getName()
            );
        }

        return ctx.proceed();
    }
}